<?php

	require_once "DbMysql.php";
	$redis = new Redis();
    //连接redis服务器
    $redis->connect('127.0.0.1', '6379');
    // 服务器配置
    $redis->auth('XusJCrwe');
    $current = 1;
    if ($num = $redis->get('current')) {
    	$current = $num;
    } else {
    	$redis->set('current', $current);
    }

	$config = array(
				'host' => '127.0.0.1',
				'port' => '3306',
				'username' => 'root',
				// 'password' => 'root',
				'password' => 'YU0bty7A',
				'db' => 'lottery'
				);
	$db = new DB($config);

	$code = getCode($db, $current, $redis);
	if ($code) {
		// echo "Success...";
		// echo "<br>";
		// echo $code;
		$respone = array('status' => 'success', 'code' => $code);
		echo json_encode($respone);
	}

	$db->close();

	// 获取识别码
	function getCode($db, $current, $redis)
	{
		$res = $db->select_one("verification_code", "codeorder=$current");
		if ($res['isget'] === "1") {
			$redis->incr('current');
			$current = $redis->get('current');
			return getCode($db, $current, $redis);
		} else {
			$code = $res['uniquestr'];
			$db->update("verification_code", array('isget'=>1), "codeorder=$current");
			$redis->incr('current');
			return $code;
		}
	}


?>